/**
 * Copyright (c) 2011 Tomi Paananen.
 *
 * Part of Quick Gestures engine library.
 */

#ifndef GESTUREMODEL_H_
#define GESTUREMODEL_H_

// Qt includes
#include <QAbstractListModel>
#include <QList>
#include <QPoint>

// qgengine includes
#include "qgenginepriv.h"

// Forward declarations
class Gesture;


class QGLIB_EXPORT GestureModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int count READ count NOTIFY countChanged)

public: // Data types

    enum GestureModelRoles {
        IdRole,
        NameRole,
        AttributesRole,
        PointsRole,
        GestureObject,
        GesturePointer,
    };

public: // Construction and destruction
    explicit GestureModel(QObject *parent = 0);
    explicit GestureModel(const GestureModel &gestureModel,
                          QObject *parent = 0);
    virtual ~GestureModel();

public: // From QAbstractListModel
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    void removeRow(int row, const QModelIndex &parent);

public:
    Q_INVOKABLE QList<Gesture*> gestures() const;
    Gesture *gestureByIndex(int index) const;
    Q_INVOKABLE Gesture *gestureById(quint32 id) const;
    Gesture *gestureByName(const QString &name) const;
    int count() const;

public slots:
    bool addGesture(Gesture *gesture);
    void setGestures(QList<Gesture*> &gestures);
    bool removeGesture(quint32 id);
    void clear();
    bool updateGestureByIndex(int index);
    QPoint pointAt(quint32 gestureId, int index) const;

protected:
    void appendGesture(Gesture *gesture);

signals:
    void countChanged(int count);

protected: // Data
    QList<Gesture*> m_gestures; // Owned
};

Q_DECLARE_METATYPE(GestureModel)


#endif // GESTUREMODEL_H

// End of file.
